// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import VueCookies from 'vue-cookies'
import ElementUI from 'element-ui'
import axios from './utils/intercept'
import 'element-ui/lib/theme-chalk/index.css';
import $ from 'jquery'
import common from './utils/common.js'
// import echarts from 'echarts'
import * as echarts from 'echarts';

import VueAreaLinekage from 'vue-area-linkage'

// Vue.prototype.global = global
Vue.prototype.common = common
Vue.prototype.echarts = echarts

import inputFilter from './utils/input.js'
Vue.directive('inputFilter', inputFilter)

Vue.config.productionTip = false
Vue.use(ElementUI)
Vue.use(VueCookies)
Vue.use(VueAreaLinekage)

Vue.prototype.$axios = axios

axios.defaults.timeout = 60000
axios.defaults.headers['Content-Type'] = 'application/json;charset=UTF-8'
axios.defaults.withCredentials = false // 跨域
axios.defaults.baseURL = 'http://127.0.0.1:8080/junyi-service/'

// 全局cookie设置过期时间30天
VueCookies.config('1d')


/* eslint-disable no-new */
window.vm = new Vue({
  el: '#app',
  router,
  components: { App },
  template: '<App/>'
})

router.beforeEach((to, from, next) => {
  try {
    // 路由发生改变修改页面的title
    if (to.meta.title) {
      document.title = to.meta.title
    }
    // this.$cookies.set('openid', res.data.openid)
    var token = VueCookies.get('token')
    // var token=''
    // if ((!token || token === 'undefined') && to.meta.requireAuth) {
      if ((!token || token === 'undefined')) {
      // if (to.path === '/login') {
      //   next()
      // } else {
      //   // global.loginshow = true
      //   next({
      //     path: '/login',
      //     query: {
      //       // redirect: to.fullPath,
      //       redirect: to.name,
      //       param: JSON.stringify(to.params)
      //     }// 将目的路由地址存入login的query中
      //   })
      //
      // }
        showLogin();
    } else {
      // global.loginshow = false
      next()
    }
  }catch (e){
    this.$message.error(e)
  }


})
